using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Windows.Data.Html;

namespace FeedReaderApp.Model
{
    public class FeedItem
    {
        public FeedItem()
        {
            Categories = new List<string>();
        }

        public string UniqueId { get; set; }

        public string FeedName { get; set; }

        public string Title { get; set; }
        public string Summary { get; set; }
        public List<string> Categories { get; set; }
        public string Content { get; set; }
        public string Uri { get; set; }
        public string InferredImageUrl { get; set; }

        [XmlIgnore]
        public string ContentReWrapped
        {
            get { return WrapHtml(Content,Uri); }
        }

        private string WrapHtml(string value,string feedUri)
        {
            value = value.Replace("target=_blank", "");
            value = value.Replace("target=_self", "");
            value = value.Replace("target=_top", "");
            value = value.Replace("target=_parent", "");
            value = value.Replace("<a", "<a target=_blank");
            var sb = new StringBuilder();
            sb.AppendLine("<html><head><style type=\"text/css\">");
            sb.AppendLine(
@"
body, p, table, td, th
 {
 background-color:#fff;
 color: #000;
 font-family:""Segoe UI"";
 font-size:12pt;
 }
body {
 column-width: 30em;
 column-gap: 2em; 
}
body, html {
 height:100%;
}
body {
 height: 95%;
}
img {
max-width:100%;
height: auto;
}
a, a.visited, a:hover {
 color: #0000ff;
}
a > img
{
border: 0px none white;
text-decoration: none;
}
img{border:0;}

");
            sb.AppendLine("</style></head><body>");
            if (feedUri != "#")
            {
                sb.Append(value + string.Format("<p><a href='{0}' target='_blank'>mehr...</a></p>", feedUri));
            }
            else
            {
                sb.Append(value);
            }
           
            
            sb.AppendLine("</body></html>");
            return sb.ToString();
        }
    }
}
